<template>
	<view class="inquiryOrderList-wrap">
		<view class="inquiryOrderList-tab">
			<!-- , '极速问诊', '开药问诊' -->
			<u-tabs v-model="activeTab" :scroll="false" :tabs="['专家问诊']" @change="tabChange"></u-tabs>
		</view>
		<u-empty-state v-if="dataTotalPage == 0" value="暂无相关问诊订单"></u-empty-state>
		<scroll-view v-else show-scrollbar="false" class="scroll-list " scroll-y @scrolltolower="scrollLoading()">
			<u-inquiry-order-item v-for="(item, index) in dataList" :key="index" :data="item"
				@click="gotoRouter('/pages-order/inquiryOrderInfo/inquiryOrderInfo?id=' + item.id)"
				@paySuccess="initData"></u-inquiry-order-item>

			<uni-load-more v-if="dataTotalPage > 1" :status="dataLoading"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
import uTab from '@/components/u-tabs/u-tabs.vue';
import uInquiryOrderItem from '../components/u-inquiry-order-item/u-inquiry-order-item.vue';
import uniLoadMore from '@/components/uni/uni-load-more/uni-load-more.vue';
import uEmptyState from '@/components/u-empty-state/u-empty-state.vue';
export default {
	components: {
		uTab,
		uInquiryOrderItem,
		uniLoadMore,
		uEmptyState
	},
	data() {
		return {
			activeTab: 0,
			pageNo: 1,
			pageSize: 20,
			dataTotalPage: 1, //数据总数
			dataLoading: 'loading', //数据加载
			dataList: []
		};
	},

	onLoad(option) { },
	onShow() {
		this.initData();
	},
	methods: {
		tabChange(e) {
			this.activeTab = e;
			this.pageNo = 1;
			this.dataList = [];
			this.dataTotalPage = 1;
			this.scrollLoading();
		},

		initData(e) {
			this.pageNo = 1;
			this.dataList = [];
			this.dataTotalPage = 1;

			this.scrollLoading();
		},

		//问诊订单列表
		myQuestionOrder() {
			this.$api
				.myQuestionOrder({
					params: {
						orderType: this.activeTab,
						pageNo: this.pageNo,
						pageSize: this.pageSize
					}
				})
				.then(res => {
					if (res.code == 200) {
						this.dataTotalPage = res.result.pages;

						if (this.pageNo == 1) {
							this.dataList = res.result.records;
						} else {
							this.dataList = this.dataList.concat(res.result.records);
						}

						if (res.result.current >= res.result.pages) {
							this.dataLoading = 'noMore';
						} else {
							this.dataLoading = 'loading';
						}
						this.pageNo++;
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		},

		//修改订单状态
		updateOrderStatus() {
			this.$api
				.updateOrderStatus({
					params: {
						orderId: this.questionOrderForm.orderId,
						status: 1
					}
				})
				.then(res => {
					if (res.code == 200) {
						this.clearQuestionOrderForm();
						this.gotoRouter('/pages-order/inquiryOrderInfo/inquiryOrderInfo?id=' + this.inquiryOrderId);
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		},

		//滚动加载
		scrollLoading() {
			if (this.pageNo <= this.dataTotalPage) {
				this.myQuestionOrder();
			}
		}
	}
};
</script>

<style lang="less">
@import './inquiryOrderList.less';
</style>
